package com.example.myhttp

import android.os.Bundle
import android.util.Log
import android.view.View
import com.example.myhttp.databinding.ActivityMainBinding
import com.example.myhttp.mvvm.BaseMVVMActivity
import com.yang.http.HttpRequest


class MainActivity : BaseMVVMActivity<ActivityMainBinding, MainViewModel>(), View.OnClickListener {
    override val layoutId: Int
        get() = R.layout.activity_main

    override fun initView(savedInstanceState: Bundle?) {

        mVDB.tvPostHttp.setOnClickListener(this)


        HttpRequest.mDefaultBaseUrl = "https://qqlykm.cn/"
        HttpRequest.addDefaultHeader("Content-Type", "application/x-www-form-urlencoded;charset:utf-8;")

        mVM.postHttpResult.observe(this) {

            Log.e("返回结果", " === " + it.toString())
            mVDB.txtShow.text = "访问成功： \n"+it.toString()

        }

        mVM.errorResult.observe(this) {

            Log.e("返回结果失败", " === " + it.toString())
            mVDB.txtShow.text =  "访问失败： \n"+it.toString()

        }



    }


    override fun onClick(view: View) {
        when (view.id) {
            R.id.tv_post_http -> {
                mVM.postApp()
            }
        }
    }


}

